using Cysharp.Threading.Tasks;

namespace IQIGame.Onigao.GamePlay
{
    public class PetViewComponent : TComponent
    {
        public UnitView unit;

        protected override void OnDispose()
        {
        }

        public override void OnCreate(TEntity entity)
        {
            this.unit = entity as UnitView;
        }

        public int petID;
        public int petSkill;
        private string _petName;
        private bool _isShowPet;

        public void Initialize(int petID)
        {
            if (petID == 0)
            {
                return;
            }
            this.petID = petID;
            var rPetConfig = TableCenter.pet.Get(petID);
            if (rPetConfig != null)
            {
                this.petSkill = rPetConfig.SkillID;
                this._petName = rPetConfig.BattleEntityAsset;
            }
        }


        public async UniTask ShowPet()
        {
            if (!string.IsNullOrEmpty(this._petName))
            {
                var rViewComp = this.unit.GetComponent<UnitViewComponent>(ETComponentType.UnitViewComponent);
                await rViewComp.Morph(this._petName, (int)EUnitType.Monster);
                this._isShowPet = true;
            }
        }

        public async UniTask HidePet()
        {
            if (this._isShowPet)
            {
                var rViewComp = this.unit.GetComponent<UnitViewComponent>(ETComponentType.UnitViewComponent);
                await rViewComp.RemoveMorph(this._petName);
                this._isShowPet = false;
            }
        }
    }
}